package com.hsurosy.domain.credit.event;

import com.hsurosy.types.event.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author Hsu琛君珩
 * @Date 2024-11-26 0:00
 * @Description 积分账户调整成功消息【充值、支付，成功消息】
 * @Version: v1.0.0
 */
@Component
public class CreditAdjustSuccessMessageEvent extends BaseEvent<CreditAdjustSuccessMessageEvent.CreditAdjustSuccessMessage> {

    @Value("${spring.rabbitmq.topic.credit_adjust_success}")
    private String topic; // RabbitMQ 消息队列主题

    /**
     * 构建事件消息对象
     *
     * @param data 包含积分调整成功信息的数据对象
     * @return 构建完成的事件消息对象，包含唯一ID、时间戳和数据内容
     */
    @Override
    public EventMessage<CreditAdjustSuccessMessage> buildEventMessage(CreditAdjustSuccessMessage data) {
        return EventMessage.<CreditAdjustSuccessMessageEvent.CreditAdjustSuccessMessage>builder()
                .id(RandomStringUtils.randomNumeric(11))
                .timestamp(new Date())
                .data(data)
                .build();
    }

    /**
     * 获取事件主题
     *
     * @return 当前事件对应的消息队列主题
     */
    @Override
    public String topic() {
        return topic;
    }

    /**
     * 积分调整成功的消息数据对象
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class CreditAdjustSuccessMessage {
        /** 用户ID */
        private String userId;
        /** 订单ID */
        private String orderId;
        /** 交易金额 */
        private BigDecimal amount;
        /** 业务仿重ID - 外部透传。返利、行为等唯一标识 */
        private String outBusinessNo;
    }

}
